<template>
  <div>
    <el-row class="">
      <el-col class="">
        <el-form ref="form"  label-position='right' size="small" :inline="true" label-width="110px">
          <el-col :span="3" >
              <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                  <el-input prefix-icon="el-icon-search" placeholder="角色名" v-model="listQuery.condition.name.value" clearable></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="4" >
              <el-form-item label="" prop="subsysid" size='small' style="margin:12px 5px;">
                  <el-select placeholder="请选择子系统"  v-model="listQuery.condition.subsysid.value" clearable @focus="editSubSystemsOptions">
                      <el-option v-for="item in subSystemsOptions" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                  </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="4" >
            <!-- 角色状态 -->
              <el-form-item label="" prop="status" size='small' style="margin:12px 5px;">
                  <el-select placeholder="请选择角色状态" v-model="listQuery.condition.status.value" clearable>
                      <el-option v-for="item in statusOptions" :key="item.key" :label="item.display_name" :value="item.key">
                      </el-option>
                  </el-select>
              </el-form-item>
            </el-col>
          <el-col :span="13">
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="success" @click="getSetedList('find')">查 询</el-button>
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="danger" icon="el-icon-edit" @click="handleResetSeted()">重 置</el-button>
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="primary" @click="handleDelete('delete')">删除角色</el-button>
             </el-col>
          </el-form>
        </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="24">
        <div>
          <div class="treeArea" style=" margin-top: 1px">
            <el-table
              :data="userData"
              height="275px"
              size="small"
              @select="selectionChangeSeted"
              @select-all="selectionChangeSeted"
              @selection-change="selectionValChangeSeted"
              style="width: 100%;border:#eeeeee">
            <el-table-column
              type="selection"
              width="120" align="center" >
            </el-table-column>
            <el-table-column align="center" label="序号" min-width="50px" type="index">
              <template slot-scope="scope">
              <span>{{scope.$index + (serialNumberSeted - 1) * listQuery.rowBounds.limit + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="角色名称" min-width="200px" prop="name">
                <template slot-scope="scope">
                    <span>{{scope.row.name}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="子系统名称" min-width="180px" prop="subsysname">
                <template slot-scope="scope">
                    <span>{{scope.row.subsysname}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="角色状态" width="100px" prop="fcTime">
                <template slot-scope="scope">
                   <span>{{scope.row.status | statusFilter}}</span>
                </template>
            </el-table-column>
            </el-table>
          </div>
          <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]"
                           :page-size="listQuery.rowBounds.limit" layout="total, sizes, prev, pager, next, jumper"
                           :total="total">
            </el-pagination>
          </div>

          <el-row :gutter="5">
            <el-col style="text-align: right; border-top:1px solid #e6e6e6; padding-top:20px; margin-top:10px;">
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="primary" @click="handleCreateBatch">添加角色</el-button>
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="primary" @click="handleCreateBatchOrg">按机构添加角色</el-button>
              <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 5px;" type="primary" @click="handleUserBatch">复制角色</el-button>
            </el-col>
          </el-row>
        </div>
      </el-col>
      <el-col :span="12"></el-col>
    </el-row>
    <el-dialog
      title="添加角色"
      :visible.sync="addDialogVisible"
      append-to-body
      top="1vh"
      width="70%">
      <el-row class="">
        <el-col class="">
          <el-form ref="form"  label-position='right' size="small" :inline="true" label-width="110px">
            <el-col :span="4" >
                <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                    <el-input prefix-icon="el-icon-search" placeholder="角色名称" v-model="listQueryUn.condition.name.value" clearable></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="4" >
                <el-form-item label="" prop="subsysid" size='small' style="margin:12px 5px;">
                    <el-select placeholder="请选择子系统"  v-model="listQueryUn.condition.subsysid.value" clearable @focus="editSubSystemsOptions">
                        <el-option v-for="item in subSystemsOptions" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="4" >
              <!-- 角色状态 -->
                <el-form-item label="" prop="status" size='small' style="margin:12px 5px;">
                    <el-select placeholder="请选择角色状态" v-model="listQueryUn.condition.status.value" clearable>
                        <el-option v-for="item in statusOptions" :key="item.key" :label="item.display_name" :value="item.key">
                        </el-option>
                    </el-select>
                </el-form-item>
              </el-col>
            <el-col :span="12">
                <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 10px;" type="success" @click="getList('find')">查 询</el-button>
                <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 10px;" type="danger" icon="el-icon-edit" @click="handleReset()">重 置</el-button>
               </el-col>
            </el-form>
          </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-table
            :data="unUserData"
            height="275px"
            size="small"
            @select="selectionChange"
            @select-all="selectionChange"
            @selection-change="selectionValChange"
            style="width: 100%;height: 370px; overflow: auto;border:#eeeeee">
            <el-table-column
              type="selection"
              width="120" align="center" >
            </el-table-column>
            <el-table-column type="index" label="序号" width="50">
              <template slot-scope="scope">
              <span>{{scope.$index + (serialNumber - 1) * listQueryUn.rowBounds.limit + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="name"
              label="角色名称"
              width="200px" align="center" >
            </el-table-column>
            <el-table-column
              prop="subsysname"
              label="子系统名称"
              width="180px" align="center" >
            </el-table-column>
            <el-table-column
              label="角色状态" align="center">
                <template slot-scope="scope">
                   <span>{{scope.row.status | statusFilter}}</span>
                </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChangeBatch"
                           @current-change="handleCurrentChangeBatch"
                           :page-sizes="[10,20,30, 50]"
                           layout="total, sizes, prev, pager, next, jumper"
                           :page-size="listQueryUn.rowBounds.limit"
                           :total="unTotal">
            </el-pagination>
          </div>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="insertList('insert')" type="primary">保 存</el-button>
        <el-button size="small" @click="addDialogVisible = false" type="primary">关 闭</el-button>
      </span>
    </el-dialog>
      <el-dialog
        title="根据组织机构添加角色"
        :visible.sync="addDialogVisibleOrg"
        append-to-body
        top="1vh"
        width="70%">
        <el-row>
          <el-col :span="8">
            <el-tree ref='tree'
               :data="treeData"
               v-loading="loading"
               style="height: 400px; overflow: scroll"
               :props="defaultProps"
               :expand-on-click-node='false'
               @node-click="handleNodeClick"
               node-key="id"
               :highlight-current='true'
               :default-expand-all='true'>
                  <span class="custom-tree-node" slot-scope="{ node, data }">
                    <span v-if="data.other.Status == 0" class="ztrrName" style="display: inline-block;" :title="data.name">{{ data.name }}</span>
                    <span v-if="data.other.Status == 1" class="ztrrName" style="display: inline-block;color:red" :title="data.name">{{ data.name }}(禁用)</span>
                    <div style="display: inline-block;" class="treeNone">
                    </div>
                   </span>
               </el-tree>
          </el-col>
          <el-col :span="16">
            <div style="margin-top:15px;">
              <div class="select-container">
                <el-row class="">
                  <el-col :span="24" class="">
                    <el-form ref="form" label-width="100px" label-position='right' size="small" :inline="true">
                    <el-col :span="5" >
                        <el-form-item label="" prop="name" size='small'  style="margin:12px 5px;">
                            <el-input prefix-icon="el-icon-search" placeholder="角色名称" v-model="listQueryDemo.condition.name.value" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5" >
                        <el-form-item label="" prop="subsysid" size='small' style="margin:12px 5px;">
                            <el-select placeholder="请选择子系统"  v-model="listQueryDemo.condition.subsysid.value" clearable @focus="editSubSystemsOptions">
                                <el-option v-for="item in subSystemsOptions" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4" >
                      <!-- 角色状态 -->
                        <el-form-item label="" prop="status" size='small' style="margin:12px 5px;">
                            <el-select placeholder="请选择角色状态" v-model="listQueryDemo.condition.status.value" clearable>
                                <el-option v-for="item in statusOptions" :key="item.key" :label="item.display_name" :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="10" style="padding-left:3px;margin-top:12px;float:right;margin-right:0">
                        <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="success" icon="el-icon-edit" @click="selectUserByOrgId()">查 询</el-button>
                        <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="danger" icon="el-icon-circle-close-outline" @click="handleResetOrg()">重 置</el-button>
                      </el-col>
                    </el-form>
                  </el-col>
                </el-row>
              </div>
            </div>
            <el-table
              :data="userDataDemo"
              size="small"
              @select-all="selectionOrgChange"
              @select="selectionOrgChange"
               @selection-change="selectionValOrgChange"
              height="330px"
              style="width: 100%;overflow: auto;border:#eeeeee">
              <el-table-column
                type="selection"
                width="30" align="center" >
              </el-table-column>
              <el-table-column type="index" label="序号" width="50" align="center">
                <template slot-scope="scope">
                <span>{{scope.$index + (serialNumberOrg - 1) * listQueryDemo.rowBounds.limit + 1}}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="name"
                label="角色名"
                width="120" align="center" >
              </el-table-column>
              <el-table-column
                prop="subsysname"
                label="子系统名称"
                width="120" align="center" >
              </el-table-column>
              <el-table-column
                label="角色状态" width="180" align="center" >
                <template slot-scope="scope">
                  {{scope.row.status | statusFilter}}
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                align="center" >
                <template slot-scope="scope">
                  <el-button @click="handleClick(scope.row)" type="text" size="small">添加</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="pagination-container">
              <el-pagination background @size-change="handleSizeChangeDemo"
                             @current-change="handleCurrentChangeDemo"
                             :page-sizes="[10,20,30, 50]"
                             :page-size="listQueryDemo.rowBounds.limit"
                             layout="total, sizes, prev, pager, next, jumper"
                             :total="totalDemo">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col align="right">
            <el-button size="small" @click="insertOrgList('insert')" type="primary">保存</el-button>
            <el-button size="small" @click="addDialogVisibleOrg = false" type="primary">关 闭</el-button>
          </el-col>
        </el-row>
    </el-dialog>
    <!--复制用户权限-->
    <el-dialog
      v-if="copyRoleDialogVisible"
      :close-on-click-modal="false"
      title="复制角色"
      :visible.sync="copyRoleDialogVisible"
      width="80%">
      <copyUserRole :copyUserRoleData="copyUserRoleData" @changeCloseDialog="changeCloseDialog"></copyUserRole>
    </el-dialog>
  </div>
</template>

<script>
import {
  batchInsertItemUser,
  SelectUserRole,
  SelectUserRoleByOrgId,
  deleteHandle,
  userSelected,
  SysOrgInfo,
  treeById
} from '@/api/systemManage/roleManagementRoleEdit'
import {
  selectSysSubsys
} from '@/api/systemManage/roleManagement'
import copyUserRole from './copyUserRole'
import {
  statusOptions,
  statusKeyValue,
  ptOptions,
  ptKeyValue
} from '@/utils/allOptions'
export default {
  components: {
    copyUserRole
  },
  name: 'editUserRole',
  props: ['editUserRoleData'],
  data() {
    return {
      total: 0,
      treeData: [],
      editUserRoleOrgData: [],
      copyUserRoleData: {
        isPt:0
      },
      loading: false,
      dialogVisible: false,
      addDialogVisible: false,
      addDialogVisibleOrg: false,
      copyRoleDialogVisible: false,
      subSystemsOptions: [],
      userDataDemo: [],
      statusOptions,
      ptOptions,
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      listQueryUn: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        condition: {
          name:{
            property: 'name',
            value: '',
            type: 'LIKE'
          },
          status: {
            property: 'status',
            value: '0',
            type: 'EQ'
          },
          subsysid:{
            'property': 'subsysid',
            'value': '',
            'type': 'EQ'
          }
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'id'
        }]
      },
      listQuery: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'id'
        }],
        condition: {
          name:{
            property: 'name',
            value: '',
            type: 'LIKE'
          },
          status: {
            property: 'status',
            value: '0',
            type: 'EQ'
          },
          subsysid:{
            'property': 'subsysid',
            'value': '',
            'type': 'EQ'
          }
        }
      },
      listQueryDemo: {
        rowBounds: {
          offset: 0,
          limit: 10
        },
        condition: {
          name:{
            property: 'name',
            value: '',
            type: 'LIKE'
          },
          status: {
            property: 'status',
            value: '0',
            type: 'EQ'
          },
          subsysid:{
            'property': 'subsysid',
            'value': '',
            'type': 'EQ'
          },
          orgId: {
            property: 'orgId',
            value: '',
            type: 'EQ'
          }
        },
        fields: [
        ],
        sort: [{
          direction: 'ASC',
          property: 'id'
        }]
      },
      totalDemo: 0,
      form: '',
      userData: [],
      unTotal: 0,
      unUserData: [],
      checkedUsers: [],
      checkedUsersSeted: [],
      serialNumber: 1,
      serialNumberOrg: 1,
      serialNumberSeted: 1,
      multipleSelection:[],
      multipleSelectionSeted:[],
    }
  },
  // 画面刚进入method
  mounted() {
    this.editSubSystemsOptions()
  },
  created() {
    if (this.editUserRoleData.isPt) {
      this.listQueryUn.isPt = 1
      this.listQuery.isPt = 1
      this.listQueryDemo.isPt = 1
      this.copyUserRoleData.isPt = 1
    }
    this.getSetedList()
  },
  filters: {
    statusFilter(target) {
      return statusKeyValue[target]
    },
    ptFilter(target) {
      return ptKeyValue[target]
    }
  },
  methods: {
    handleDelete(flag) {
    if (this.checkedUsersSeted.length > 0) {
        deleteHandle(this.checkedUsersSeted).then(response => {
          this.getSetedList(flag)
          this.$message({
            message: '批量删除成功',
            type: 'success'
          })
        })
        this.checkedUsersSeted = [];
      } else {
          this.$message({
            message: '请选择人员',
            type: 'warning'
          })
      }
    },
    // 翻页器使用
    handleSizeChange(val) {
      this.listQuerypage = 1
      this.listQuery.rowBounds.limit = val
      this.listQuery.rowBounds.offset = this.listQuery.rowBounds.limit * (this.serialNumberSeted - 1)
      this.getSetedList()
    },
    // 翻页器使用
    handleCurrentChange(val) {
      this.serialNumberSeted = val
      this.listQuerypage = val
      this.listQuery.rowBounds.offset =
        this.listQuery.rowBounds.limit * (val - 1)
      this.getSetedList()
    },
    // 翻页器使用
    handleSizeChangeBatch(val) {
      this.listQueryUn.rowBounds.limit = val
      this.listQueryUn.rowBounds.offset = this.listQueryUn.rowBounds.limit * (this.serialNumber - 1)
      this.listQueryUn.isExist = 0
      SelectUserRole(this.listQueryUn).then(response => {
        this.unUserData = response.data.data.records
        this.unTotal = response.data.data.count
      })
    },
    // 翻页器使用
    handleCurrentChangeBatch(val) {
      this.serialNumber = val
      this.listQueryUn.rowBounds.offset =
        this.listQueryUn.rowBounds.limit * (val - 1)
        this.listQueryUn.isExist = 0
        SelectUserRole(this.listQueryUn).then(response => {
          this.unUserData = response.data.data.records
          this.unTotal = response.data.data.count
      })
    },
    // 翻页器使用(按组织机构添加人员)
    handleSizeChangeDemo(val) {
      this.listQueryDemo.rowBounds.limit = val
      this.listQueryDemo.rowBounds.offset = this.listQueryDemo.rowBounds.limit * (this.serialNumberOrg - 1)
      this.listQueryDemo.isExist = 0
      this.selectUserByOrgId()
    },
    // 翻页器使用(按组织机构添加人员)
    handleCurrentChangeDemo(val) {
        this.serialNumberOrg = val
        this.listQueryDemo.rowBounds.offset =
        this.listQueryDemo.rowBounds.limit * (val - 1)
        this.listQueryDemo.isExist = 0
        this.selectUserByOrgId()
    },
     selectUserByOrgId() {
        SelectUserRoleByOrgId(this.listQueryDemo).then(response => {
          this.userDataDemo = response.data.data.records
          this.totalDemo = response.data.data.count
        })
     },
    handleCreateBatch() {
      this.addDialogVisible = true
      this.getList()
    },
    handleUserBatch() {
      if (this.checkedUsersSeted.length > 0) {
        this.copyRoleDialogVisible = true
      } else {
        this.$message({
          message: '请选择要配置的角色。',
          type: 'warning'
        })
      }
    },
     selectionOrgChange(val,row) {
       this.checkedOrgUsers=[];
       if(val){
         for(var i in val){
             var tempUserRoleOrg = {
               roleId: '',
               userId: '',
               orgId: ''
             }
            tempUserRoleOrg.roleId = val[i].id
            tempUserRoleOrg.userId = this.editUserRoleData.userId
            tempUserRoleOrg.orgId = this.editUserRoleData.userOrgId
            this.checkedOrgUsers.push(tempUserRoleOrg)
         }
       }

     },
     selectionValOrgChange(val) {
      this.multipleOrgSelection = val
     },
    handleCreateBatchOrg() {
      this.addDialogVisibleOrg = true
      this.getTree()
    },
    getTree() {
      treeById({ id: this.$store.getters.rootOrgId }).then(response => {
        this.treeData = response.data.data
        if (this.$store.state.user.selectRoleOrgIdByOrg) {
          this.$nextTick(() => {
            if (this.editUserRoleData.isPt) {
              this.$refs.tree.setCurrentKey(this.$store.state.user.selectRoleOrgIdByOrgPt) // treeBox 元素的ref   value 绑定的node-key
            } else {
              this.$refs.tree.setCurrentKey(this.$store.state.user.selectRoleOrgIdByOrg) // treeBox 元素的ref   value 绑定的node-key
            }
          })
          if (this.editUserRoleData.isPt) {
            this.listQueryDemo.orgId = this.$store.state.user.selectRoleOrgIdByOrgPt
            this.listQueryDemo.condition.orgId.value = this.$store.state.user.selectRoleOrgIdByOrgPt
          } else {
            this.listQueryDemo.orgId = this.$store.state.user.selectRoleOrgIdByOrg
            this.listQueryDemo.condition.orgId.value = this.$store.state.user.selectRoleOrgIdByOrg
          }
          this.listQueryDemo.userId = this.editUserRoleData.userId
          this.listQueryDemo.isExist = 0
          this.selectUserByOrgId()
         }
      })
    },
    getList(flag) {
      this.listLoading = true
      this.listQueryUn.userId = this.editUserRoleData.userId
      this.listQueryUn.orgId = this.editUserRoleData.userOrgId
      this.listQueryUn.isExist = 0
      if (flag ==='find') {
        this.checkedUsers = [];
        this.listQueryUn.rowBounds.offset = 0
        this.unTotal = 0
        this.serialNumber = 1
      }
      if (flag ==='insert') {
        if ((this.listQueryUn.rowBounds.offset == (this.unTotal - 1)
        || this.unUserData.length == this.multipleSelection.length)
         && this.listQueryUn.rowBounds.offset >= this.listQueryUn.rowBounds.limit) {
          if (this.serialNumber * this.listQueryUn.rowBounds.limit >= this.unTotal) {
            this.listQueryUn.rowBounds.offset -=this.listQueryUn.rowBounds.limit
            this.serialNumber -=1
          }
        }
      }
      const that = this
      SelectUserRole(this.listQueryUn).then(response => {
        this.unUserData = response.data.data.records //未设置角色
        this.unTotal = response.data.data.count
        this.listLoading = false
      })
    },
    getSetedList(flag) {
      if (flag ==='find') {
        this.checkedUsersSeted = [];
        this.listQuery.rowBounds.offset = 0
        this.total = 0
        this.serialNumberSeted = 1
      }

      if (flag ==='delete') {
        if ((this.listQuery.rowBounds.offset == (this.total - 1)
        || this.userData.length == this.multipleSelectionSeted.length)
         && this.listQuery.rowBounds.offset >= this.listQuery.rowBounds.limit) {
          if (this.serialNumberSeted * this.listQueryUn.rowBounds.limit >= this.total) {
            this.listQuery.rowBounds.offset -=this.listQuery.rowBounds.limit
            this.serialNumberSeted -=1
          }
        }
      }
      this.loading = true
      this.listQuery.userId = this.editUserRoleData.userId
      this.listQuery.orgId = this.editUserRoleData.userOrgId
      this.listQuery.isExist = 1
      SelectUserRole(this.listQuery).then(response => {
        this.userData = response.data.data.records
        this.total = response.data.data.count
        this.loading = false
      })
    },
    closeSelf() {
      this.$emit('changeCloseDialog')
    },
    insertList(flag) {
      if (this.checkedUsers.length > 0) {
        batchInsertItemUser(this.checkedUsers).then(response => {
          // 已选人员
          this.getSetedList()
          // 未选人员
          this.getList(flag)
          this.$message({
            message: '批量添加成功',
            type: 'success'
          })
        })
        this.checkedUsers=[];
       } else {
          this.$message({
            message: '请选择人员。',
            type: 'warning'
          })
       }
    },
     insertOrgList(flag) {
     if (this.checkedOrgUsers.length > 0) {
         batchInsertItemUser(this.checkedOrgUsers).then(response => {
          // 已选人员
          this.getSetedList()

          if (flag ==='insert') {
            if ((this.listQueryDemo.rowBounds.offset == (this.totalDemo - 1)
            || this.userDataDemo.length == this.multipleOrgSelection.length)
             && this.listQueryDemo.rowBounds.offset >= this.listQueryDemo.rowBounds.limit) {
             if (this.serialNumberOrg * this.listQueryDemo.rowBounds.limit >= this.totalDemo) {
                this.listQueryDemo.rowBounds.offset -=this.listQueryDemo.rowBounds.limit
                this.serialNumberOrg -=1
              }
            }
          }

          // 未选人员
          this.listQueryDemo.userId = this.editUserRoleData.userId
          if (this.editUserRoleData.isPt) {
            this.listQueryDemo.orgId = this.editUserRoleData.userOrgId
          }
          this.listQueryDemo.isExist = 0
          this.selectUserByOrgId()
          this.$message({
            message: '按机构批量添加成功',
            type: 'success'
          })
         })
          this.checkedOrgUsers=[];
       } else {
          this.$message({
            message: '请选择人员',
            type: 'warning'
          })
       }
     },
    handleClick(row) {
      var rowDemo = [
        {
          userId: this.editUserRoleData.userId,
          roleId: row.id,
          orgId: this.editUserRoleData.userOrgId
        }
      ]
      SysOrgInfo(rowDemo).then(response => {
        if (this.listQueryDemo.rowBounds.offset == (this.totalDemo - 1)
         && this.listQueryDemo.rowBounds.offset >= this.listQueryDemo.rowBounds.limit) {
          if (this.serialNumberOrg * this.listQueryDemo.rowBounds.limit >= this.totalDemo) {
            this.listQueryDemo.rowBounds.offset -=this.listQueryDemo.rowBounds.limit
            this.serialNumberOrg -=1
          }
        }
        this.listQueryDemo.condition.orgId.value= row.orgId
        if (this.editUserRoleData.isPt) {
          this.listQueryDemo.orgId = this.editUserRoleData.userOrgId
        }
        this.listQueryDemo.userId = this.editUserRoleData.userId
        this.listQueryDemo.isExist = 0
        this.selectUserByOrgId()
        // 已选人员
        this.getSetedList()
        this.$message({
          message: '添加成功',
          type: 'success'
        })
      })
    },
    editSubSystemsOptions() {
      const query = {
        sort: [
          {
            direction: 'ASC',
            property: 'id'
          }
        ]
      }
      selectSysSubsys(query).then(response => {
        const records = response.data.data.records
        if (response.data.data.count > 0) {
          this.subSystemsOptions = []
          for (const item of records) {
            const input = {}
            input.id = item.id
            input.name = item.name
            this.subSystemsOptions.push(input)
          }
        }
      })
    },
     selectionChange(val,row) {
       this.checkedUsers=[];
       if(val){
         for(var i in val){
             var tempUserRoleOrg = {
               roleId: '',
               userId: '',
               orgId: ''
             }
            tempUserRoleOrg.roleId = val[i].id
            tempUserRoleOrg.userId = this.editUserRoleData.userId
            tempUserRoleOrg.orgId = this.editUserRoleData.userOrgId
            this.checkedUsers.push(tempUserRoleOrg)
         }
       }
     },
     selectionValChange(val) {
      this.multipleSelection = val
     },
     selectionChangeSeted(val,row) {
       this.checkedUsersSeted=[];
       this.copyUserRoleData.roles=[];
       if(val){
         for(var i in val){
             var tempUserRoleOrg = {
               roleId: '',
               userId: '',
               orgId: ''
             }
            tempUserRoleOrg.roleId = val[i].id
            tempUserRoleOrg.userId = this.editUserRoleData.userId
            tempUserRoleOrg.orgId = this.editUserRoleData.userOrgId
            this.checkedUsersSeted.push(tempUserRoleOrg)
            this.copyUserRoleData.roles.push(val[i].id)
         }
       }
     },
     selectionValChangeSeted(val) {
      this.multipleSelectionSeted = val
     },
    handleNodeClick(data) {
      this.checkedOrgUsers=[];
      this.serialNumberOrg =1
      this.listQueryDemo.rowBounds.offset =0
      this.totalDemo =0
      this.listQueryDemo.condition.orgId.value = data.id
      this.listQueryDemo.userId = this.editUserRoleData.userId
      if (this.editUserRoleData.isPt) {
        this.$store.commit('SET_SELECTROLEORGID_BYORGID_PT', data.id)
      } else {
        this.$store.commit('SET_SELECTROLEORGID_BYORGID', data.id)
      }
      this.listQueryDemo.isExist = 0
      this.selectUserByOrgId()
    },
     handleResetSeted() {
       this.checkedUsersSeted=[];
       this.listQuery.condition.name.value = ''
       this.listQuery.condition.subsysid.value = ''
       this.listQuery.condition.status.value = '0'
       this.listQuery.rowBounds.offset = 0
       this.listQuery.rowBounds.limit = 10
       this.total = 0
       this.serialNumberSeted = 1
       this.getSetedList()
     },
     handleReset() {
       this.checkedUsers=[];
       this.listQueryUn.condition.name.value = ''
       this.listQueryUn.condition.subsysid.value = ''
       this.listQueryUn.condition.status.value = '0'
       this.listQueryUn.rowBounds.offset = 0
       this.listQueryUn.rowBounds.limit = 10
       this.unTotal = 0
       this.serialNumber = 1
       this.getList()
     },
     handleResetOrg() {
       this.checkedOrgUsers=[];
       this.listQueryDemo.condition.name.value = ''
       this.listQueryDemo.condition.subsysid.value = ''
       this.listQueryDemo.condition.status.value = '0'
       this.listQueryDemo.rowBounds.offset = 0
       this.listQueryDemo.rowBounds.limit = 10
       this.totalDemo = 0
       this.serialNumberOrg = 1
       this.selectUserByOrgId()
     },
    changeCloseDialog() {
      this.copyRoleDialogVisible = false
    }
  }
}
</script>

<style scoped>
.treeArea {
    max-height: 66vh;
    overflow-y: auto;
}
</style>
